project(
    'quadrature-fortran',
    'fortran',
    version : '0.1.0',
    license : 'BSD-3-Clause',
    default_options : ['buildtype=debugoptimized', 'warning_level=3'],
)

quadrature_fortran_src = files(
    'src/quadrature_module.F90',
)

quadrature_fortran_lib = library(
    meson.project_name(),
    sources : quadrature_fortran_src,
    version : meson.project_version(),
    install : true,
)

quadrature_fortran_inc = quadrature_fortran_lib.private_dir_include()
quadrature_fortran_dep = declare_dependency(
    link_with : quadrature_fortran_lib,
    include_directories : quadrature_fortran_inc,
)

test(
    'quadrature_fortran_check',
    executable(
        'quadrature_fortran_check',
        'test/test.f90',
        dependencies : quadrature_fortran_dep,
    ),
)

quadrature_fortran_lic = files('LICENSE')
install_data(
    quadrature_fortran_lic,
    install_dir : get_option('datadir')/'licenses'/meson.project_name(),
)
if host_machine.system() == 'windows'
    symbols_file = 'lib'+meson.project_name()+'-'+meson.project_version().split('.')[0]+'.dll.symbols'
    obj_suffix = '.obj'
else
    symbols_file = 'lib'+meson.project_name()+'.so.'+meson.project_version()+'.symbols'
    obj_suffix = '.o'
endif
install_subdir(quadrature_fortran_lib.path()+'.p',
    install_dir: 'include'/meson.project_name(),
    strip_directory: true,
    exclude_files: [
        'depscan.dd',
        meson.project_name()+'-deps.json',
        symbols_file,
        meson.project_name()+'.dat',
        'src_quadrature_module.F90'+obj_suffix,
    ]
)
pkg = import('pkgconfig')
pkg.generate(
    quadrature_fortran_lib,
    name: meson.project_name(),
    description: 'Adaptive Gaussian Quadrature with Modern Fortran',
    version: meson.project_version(),
    subdirs: meson.project_name(),
)
